home *** CD-ROM | disk | FTP | other *** search
- Random routines written by Charles Brabec
- for use with IBM PASCAL compiler and DOS 2.x
-
-
-
- ************************************************************************
- *** The following code is used to allow a PASCAL program to generate ***
- *** random numbers. ***
- *** ---------------------------------------------------------------- ***
- *** To use this, just insert the code below into a program and , ***
- *** after compiling the program, link the program's .OBJ file with ***
- *** the RN1.OBJ & RN2.OBJ files. To call the function in a program, ***
- *** type: INTEGER_RESULT_VARIABLE:= RND(INTEGER_VARIABLE); ***
- *** The function will generate a number batween 1 and the INT_VAR ***
- *** and will place it in the result variable. ***
- *** NOTE: Both variables must be declared as INTEGER and the one ***
- *** entering the function must be positive and >0 ***
- ************************************************************************
-
-
- { code begins with the next line }
- Function rnd(value:integer):integer;
- var
- dummy,
- time:word;
- low,high:integer;
- rand:real;
-
- function clock(dum:word):word; external;
-
- function wrd2lw(wrd:word):integer; external;
-
- function wrd2hi(wrd:word):integer; external;
-
- begin
- time:=clock(dummy);
- low:=wrd2lw(time);
- high:=wrd2hi(time);
- rand:=high+(low/255);
- rand:=sin(rand);
- rand:=abs(rand);
- rand:=trunc(rand*value)+1;
- rnd:=rand;
- end;